package com.cskaoyan.order.api;

import com.cskaoyan.mall.commons.result.ServiceCallResponse;
import com.cskaoyan.mall.commons.result.ServiceCallResponseUtil;
import com.cskaoyan.order.service.PayOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class PayOrderApImpl {

    @Autowired
    PayOrderService payOrderService;


    /**
     * 1.根据订单id修改订单状态 为已支付
     * 2.查询订单中，所有的订单商品条目，针对每一个条目下单的数量，扣减lock_count
     * @param orderId
     * @return
     */
    // 定义方法接受调用请求
    @PutMapping(value = "/rpc/pay/success")
    ServiceCallResponse payOrderSuccess(@RequestParam("orderId") String orderId) {
        // 2. 修改订单状态为已支付
        // 3.
        try {
            payOrderService.paySuccessAfter(orderId);
        } catch (Exception e) {
            e.printStackTrace();
            return new ServiceCallResponseUtil<>().fail("数据库异常");
        }
        return new ServiceCallResponseUtil<>().ok(null);
    }

}
